<?php 
require dirname(__FILE__).'/include/common.inc.php';
include dirname(__FILE__).'/include/db_mssql.class.php';
define('SINGE_PAGE',25);
$catid=$_GET['id'];
$page=isset($_GET['page'])?$_GET['page']:1;
$like=isset($_GET['sp'])?(' and bt like \'%'.iconv('UTF-8','GBK',rawurldecode($_GET['sp']).'\'')):'';

$mssql=new db_mssql();
$mssql->connect('222.73.91.35','VSAT','vsat@tsts','VsatData');


$where='lb = \''.$catid.'\''.$like;

$sql_sum='select count(*) as sum_all from zx_articles where '.$where.'';
$count=$GLOBALS['mssql']->select($sql_sum);
$count=($count[0]['sum_all']>100)?100:$count[0]['sum_all'];
$allPages=floor($count/SINGE_PAGE);
	
$page=isset($_GET['page'])?intval($_GET['page']):1;
if($page>$allPages){$page=$allPages;}else if($page<1){$page=1;}
$pages=pages2($page,$allPages);

$list_news_sql='select * from (select top '.SINGE_PAGE.' * from (SELECT Top '.($page*SINGE_PAGE).' gxrq, cc as copyfrom,zz as author,convert(varchar(100),gxrq,120) as inputtime ,lb as catid,\'category.php?id=\'+lb as curl, \'article.php?id=\'+wj as url,bt as title FROM zx_articles WHERE '.$where.' order by gxrq desc)b order by gxrq asc)a order by gxrq desc';
require_once "../class/Cache.php";
$cache=new Cache('../cache');
$cache_name=$list_news_sql;
if(time()-$cache->cache_time($cache_name)>300)
{
	$data=$mssql->select($list_news_sql);
	$cache->store($cache_name,$data);
}
else
{
	$data=$cache->fetch($cache_name);
}
foreach($data as &$value)
{
	$value['title']=iconv('GBK','UTF-8',$value['title']);
	$value['copyfrom']=iconv('GBK','UTF-8',$value['copyfrom']);
	$value['inputtime']=strtotime($value['inputtime']);
}
$categoryName=isset($categoryName[$catid])?$categoryName[$catid]:$_GET['title'];
$number=$rows=$num;

include template('phpcms', 'list_news');
cache_page(CACHE_PAGE_CONTENT_TTL);

function pages2($page,$apages)
{
	for($i=1;$i<=$apages;$i++)
	{
		if($page==$i)
		{
			$pages[]='<span>'.$i.'</span>';
		}
		else
		{
			$pages[]='<a href="?id='.$_GET['id'].'&page='.$i.'">'.$i.'</a>';
		}
	}
	return join("",$pages);
}
?>